-
-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Switch all markdown rendering to react-remark #2872
Conversation
Current dependencies on/for this PR:
This stack of pull requests is managed by Graphite. |
5ff3378
to
b1f2f96
Compare
7a3fe54
to
002618e
Compare
387b8de
to
0e1f343
Compare
002618e
to
5d10eda
Compare
3ac6675
to
e92588c
Compare
packages/@ourworldindata/components/src/MarkdownTextWrap/MarkdownTextWrap.test.ts
Outdated
Show resolved
Hide resolved
packages/@ourworldindata/components/src/MarkdownTextWrap/MarkdownTextWrap.tsx
Outdated
Show resolved
Hide resolved
function convertMarkdownRootToIRTokens( | ||
node: Root, | ||
fontParams?: IRFontParams | ||
): IRToken[] { | ||
return node.children.flatMap((item) => | ||
convertMarkdownNodeToIRTokens(item, fontParams) | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to inline this into convertMarkdownToIRTokens
- but you decide :)
Just noticed that this goes wrong on http://staging-site-switch-markdown-renderer/grapher/days-since-100th-covid-case: |
4dc9fe3
to
6c06232
Compare
01111b6
to
3e3744f
Compare
@@ -15,6 +15,7 @@ import { TextWrap } from "../TextWrap/TextWrap.js" | |||
import fromMarkdown from "mdast-util-from-markdown" | |||
import type { Root, Content } from "mdast" | |||
import { match } from "ts-pattern" | |||
import { dropRightWhile, dropWhile } from "lodash" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this right here will increase bundlesize quite a bit - make sure to import lodash via Util.ts
always.
We should probably get rid of that annoyance at some point, but for now that's how it goes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really? Our bundlewatch GA didn't show any increase. I thought that importing { _ } from "lodash"
was the big no-no. What am I missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah you're right!
I was missing my own change half a year ago 😬
Merge activity
|
Also fixed a few other issues
…ownTextWrap.tsx Co-authored-by: Marcel Gerber <[email protected]>
6c06232
to
f239a48
Compare
531cc39
to
3863877
Compare
This PR continues replacing our old custom markdown subset parser with react-remark and related functions.
We want to keep rendering markdown inside Grapher as svg text that is limited vs what markdown can offer and we have some existing svg text measuring and line break logic that we don't want to replace. To keep the changes to a relative minimum I therefore decided to translate the mdast elements to IRToken ones so that the existing logic can mostly stay in place.
Note that we are not using the latest version of mdast and related libraries as they switched to ESM only in Summer 2021 and our server admin project for example doesn't work with that yet.
The SVG tester shows quite a number of differences - I recommend reviewing the differences on the follow up branch that adds plain url parsing. Once the plain URL parsing is added, the following differences in chart subtitle/footnote rendering remain:
1) bla
or- bla
then this is now condensed into a single line and there is a weird backslash. There are 2 charts that do this that I saw in the svg tester but they are old covid charts so I think this is fine for now. We can reconsider if we want to allow lists/bullet points in subtitles in the future